<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>表</title>
<link rel="stylesheet" type="text/css" href="../easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="../easyui/demo/demo.css">
<script type="text/javascript" src="../easyui/jquery.min.js"></script>
<script type="text/javascript" src="../easyui/jquery.easyui.min.js"></script>
</head>
<body class="easyui-layout">
<div data-options="region:'north',border:false" style="height:60px;background:#B3DFDA;padding:10px"><h2>无垠式代码生成器生成结果</h2></div>
<div data-options="region:'west',split:true,title:'主菜单'" style="width:156px;padding:0px;">
<div class="easyui-accordion" data-options="fit:true,border:false">
<div title="域对象清单" style="padding:0px" data-options="selected:true">
<div id="mmadmin" data-options="inline:true" style="width: 142px; height: 98%; overflow: hidden; left: 0px; top: 0px; outline: none; display: block;" class="menu-top menu-inline menu easyui-fluid" tabindex="0"><div class="menu-line" style="height: 122px;"></div>
<div onclick="window.location='../pages/index.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">主页</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/excelWizard.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">生成代码</div><div class="menu-icon icon-add"></div></div>

<div onclick="window.location='../pages/tables.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">表</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/fields.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">字段</div><div class="menu-icon icon-add"></div></div>
</div>
</div>
</div>
</div>
<div data-options="region:'east',split:true,collapsed:true,title:'属性'" style="width:250px;overflow: hidden">
</div>
<div data-options="region:'south',border:false" style="height:50px;background:#A9FACD;padding:10px;text-align: center">火箭船软件工作室版权所有。作者电邮:jerry_shen_sjf@qq.com QQ群:277689737</div>
<div data-options="region:'center',title:'表清单'">
<div title="搜索面板" class="easyui-panel" style="width:1120px;height:200px">
<form id="ffsearch" method="post">
<table cellpadding="5">
<tr>
<td>数据库名:</td><td><input  class='easyui-textbox' type='text' name='databaseName' id='databaseName' value='' data-options="required:false"/></td>
<td>描述:</td><td><input class='easyui-textbox' type='text' name='description' id='description' value='' data-options="required:false"/></td>
<td>表名:</td><td><input class='easyui-textbox' type='text' name='tableName' id='tableName' value='' data-options="required:false"/></td></tr>
</tr>
<tr>
<td>活跃:</td><td><input  class='easyui-textbox' type='text' name='active' id='active' value='' data-options="required:false"/></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr><td colspan="3"><a href="javascript:void(0)" class="easyui-linkbutton" onclick="searchTablesByFieldsByPage()">搜索</a></td></tr>
</table>
</form>
</div>
<table id="dg" class="easyui-datagrid" title="表清单" style="width:1120px;height:400px" data-options="singleSelect:false,url:'../facade/listAllTablesFacade',method:'post',pagination:false,toolbar:toolbar">
<thead>
<tr>
<th data-options="field:'id',checkbox:true">序号</th>
<th data-options="field:'databaseName',width:80">数据库名</th>
<th data-options="field:'description',width:80">描述</th>
<th data-options="field:'tableName',width:80">表名</th>
<th data-options="field:'active',width:80">活跃</th>
</tr>
</thead>
</table>
</div>

<div class="easyui-window" title="新增表" id="waddTable" data-options="iconCls:'icon-save',modal:true,closed:true" style="width:550px;height:600px">
<div style="padding:10px 60px 20px 60px">
<form id="ff" method="post">
<table cellpadding="5">
<tr><td>数据库名:</td><td><input  class='easyui-textbox' type='text' name='databaseName' id='databaseName' value='' data-options="required:false"/></td></tr>
<tr><td>描述:</td><td><input  class='easyui-textbox' type='text' name='description' id='description' value='' data-options="required:false"/></td></tr>
<tr><td>表名:</td><td><input  class='easyui-textbox' type='text' name='tableName' id='tableName' value='' data-options="required:false"/></td></tr>
<tr><td>活跃:</td><td><input class='easyui-radio' type='radio' name='active' id='active' value='true' checked='true'/>True<input type='radio' class='easyui-radio' name='active' id='active' value='false'/>False</td></tr>
</table>
</form>
<div style="text-align:center;padding:5px">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="addTable()">新增</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">清除</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#waddTable').window('close')">取消</a>
</div>
</div>

<div class="easyui-window" title="编辑表" id="wupdateTable" data-options="iconCls:'icon-save',modal:true,closed:true" style="width:500px;height:500px">
<div style="padding:10px 60px 20px 60px">
<form id="ffedit" method="post">
<input  type='hidden' name='id' id='id' value=''/>
<table cellpadding="5">
<tr><td>数据库名:</td><td><input  class='easyui-textbox' type='text' name='databaseName' id='databaseName' value='' data-options="required:false"/></td></tr>
<tr><td>描述:</td><td><input  class='easyui-textbox' type='text' name='description' id='description' value='' data-options="required:false"/></td></tr>
<tr><td>表名:</td><td><input  class='easyui-textbox' type='text' name='tableName' id='tableName' value='' data-options="required:false"/></td></tr>
<tr><td>活跃:</td><td><input class='easyui-radio' type='radio' name='active' id='active' value='true' checked='true'/>True<input type='radio' class='easyui-radio' name='active' id='active' value='false'/>False</td></tr>
</table>
</form>
<div style="text-align:center;padding:5px">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="updateTable()">编辑</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#ffedit').form('clear');">清除</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#wupdateTable').window('close')">取消</a>
</div>
</div>

<div class="easyui-window" title="编辑数据库" id="wupdateDb" data-options="iconCls:'icon-save',modal:true,closed:true" style="width:500px;height:500px">
<div style="padding:10px 60px 20px 60px">
<form id="ffdbedit" method="post">
<input  type='hidden' name='id' id='id' value=''/>
<table cellpadding="5">
<tr><td>数据库链接:</td><td><input  class='easyui-textbox' type='text' name='dbLink' id='dbLink' value='' data-options="required:false"/></td></tr>
<tr><td>数据库名:</td><td><input  class='easyui-textbox' type='text' name='dbName' id='dbName' value='' data-options="required:false"/></td></tr>
<tr><td>用户名:</td><td><input  class='easyui-textbox' type='text' name='userName' id='userName' value='' data-options="required:false"/></td></tr>
<tr><td>，密码:</td><td><input  class='easyui-textbox' type='text' name='password' id='password' value='' data-options="required:false"/></td></tr>
</table>
</form>
<div style="text-align:center;padding:5px">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="updateDbSettings()">编辑</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#ffdbedit').form('clear');">清除</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#wupdateDb').window('close')">取消</a>
</div>
</div>
</body>
<script type="text/javascript">
var params = {};
var pagesize = 10;
var pagenum = 1;
var toolbar = [
{
	text:'编辑数据库',
	iconCls:'icon-edit',
	handler:function(){ 
		var dbSettings = lookupDbSettings();
		$("#ffdbedit").find("#dbLink").textbox("setValue",dbSettings["dbLink"]);
		$("#ffdbedit").find("#dbName").textbox("setValue",dbSettings["dbName"]);
		$("#ffdbedit").find("#userName").textbox("setValue",dbSettings["userName"]);
		$("#ffdbedit").find("#password").textbox("setValue",dbSettings["password"]);
		$('#wupdateDb').window('open');
	}
}
];
$(document).ready(function(){
$("#dg").datagrid("load");
});
function clearForm(){
$('#ff').form('clear');
}
function addTable(){
	if ($("#ff").form("validate")) {
		$.ajax({
			type: "post",
			url: "../facade/addTableFacade",
			data:{
				databaseName:$("#ff").find("#databaseName").val(),
				description:$("#ff").find("#description").val(),
				tableName:$("#ff").find("#tableName").val(),
				active:parseBoolean($("#ff").find("input[name='active']:checked").val()),
			},
			success: function(data, textStatus) {
				if (data.success) {
					$('#ff').form('clear');
					$("#ff").find("input[name='active']").get(0).checked = true;
					$("#waddTable").window('close');
					$("#dg").datagrid("load");
				}
				},
			complete : function(XMLHttpRequest, textStatus) {
			},
			error : function(XMLHttpRequest,textStatus,errorThrown) {
				alert("Error:"+textStatus);
				alert(errorThrown.toString());
			}
		});
	}
}

function updateTable(){
	$.ajax({
		type: "post",
		url: "../facade/updateTableFacade",
		data:{
			databaseName:$("#ffedit").find("#databaseName").val(),
			description:$("#ffedit").find("#description").val(),
			tableName:$("#ffedit").find("#tableName").val(),
			active:parseBoolean($("#ffedit").find("input[name='active']:checked").val()),
			id:$("#ffedit").find("#id").val(),
		},
		success: function(data, textStatus) {
			if (data.success){
				$('#ffedit').form('clear');
				$("#ffedit").find("input[name='active']").get(0).checked = true;
				$("#wupdateTable").window('close');
				$("#dg").datagrid("load");
			}
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	}); 
}

function softDeleteTable(id){
	$.ajax({
		type: "post",
		url: "../facade/softDeleteTableFacade",
		data: {
			"id":id	
		},
		dataType: 'json',
		success: function(data, textStatus) {
			$("#dg").datagrid("load");
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function deleteTable(id){
	$.ajax({
		type: "post",
		url: "../facade/deleteTableFacade",
		dataType: 'json',
		data:{"id":id},
		success: function(data, textStatus) {
			$("#dg").datagrid("load");
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	}); 
}

function toggleTable(id){
	$.ajax({
		type: "post",
		url: "../facade/toggleTableFacade",
		data: {
			"id":id
		},
		dataType: 'json',
		success: function(data, textStatus) {
			$("#dg").datagrid("load");
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function toggleOneTable(id){
	$.ajax({
		type: "post",
		url: "../facade/toggleOneTableFacade",
		data: {
			"id":id
		},
		dataType: 'json',
		success: function(data, textStatus) {
			$("#dg").datagrid("load");
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function softDeleteAllTables(ids){
	$.ajax({
		type: "post",
			url: "../facade/softDeleteAllTablesFacade",
			data: {
				ids:ids
			},
			dataType: 'json',
			success: function(data, textStatus) {
				$("#dg").datagrid("load");
			},
			complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function deleteAllTables(ids){
	$.ajax({
		type: "post",
		url: "../facade/deleteAllTablesFacade",
		data: {
			ids:ids
		},
		dataType: 'json',
		success: function(data, textStatus) {
			$("#dg").datagrid("load");
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function searchTablesByFieldsByPage(){
	params = {
		databaseName:$("#ffsearch").find("#databaseName").val(),
		description:$("#ffsearch").find("#description").val(),
		tableName:$("#ffsearch").find("#tableName").val(),
		active:parseBoolean($("#ffsearch").find("#active").val()),
	};
	$("#dg").datagrid({queryParams:params});
}

function lookupDbSettings(){
	var settings = {};
	$.ajax({
		type: "post",
		url: "../facade/lookupDbSettingsFacade",
		dataType: 'json',
		async:false,
		success: function(data, textStatus) {
			if (data.success){
				settings = data.rows;
			}
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
	return settings;
}

function updateDbSettings(){
	$.ajax({
		type: "post",
		url: "../facade/updateDbSettingsFacade",
		dataType: 'json',
		data: {
			dbLink: $('#ffdbedit').find("#dbLink").val(),
			dbName: $('#ffdbedit').find("#dbName").val(),
			userName: $('#ffdbedit').find("#userName").val(),
			password: $('#ffdbedit').find("#password").val()
		},
		success: function(data, textStatus) {
			if (data.success){
				$('#wupdateDb').window('close');
				$("#dg").datagrid("load");
			}
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function parseBoolean(val){
	if (val == undefined|| val == null) return false;
	var isInt = /^(-}+)?\d+$/.test(val);
	if (isInt&& val == "0") return false;
	else if (isInt&& val == "1") return true;
	else if (val.toLowerCase() == "false") return false;
	else if (val.toLowerCase() == "true") return true;
	else if (val.toLowerCase() == "f") return false;
	else if (val.toLowerCase() == "t") return true;
	else if (val.toLowerCase() == "n") return false;
	else if (val.toLowerCase() == "y") return true;
	else if (val.toLowerCase() == "no") return false;
	else if (val.toLowerCase() == "yes") return true;
	else return "";
}
function isBlank(val){
	if (val == undefined|| val == null || val == "") return true;
	else return false;
}
function checkRadioBoxValue(control,field,fieldvalue){
	var checkboxs = $("#"+control).find("input[name='"+field+"']");
	for (var i=0;i<checkboxs.size();i++){
		if (checkboxs.get(i).value == ""+fieldvalue) checkboxs.get(i).checked=true;
	}
}
</script>
</html>
